﻿package mortal.game.view.common.display
{
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import mortal.common.*;

    public class BitmapNumberTextRolling extends GSprite
    {
        private var _tween:TweenMax;
        private var _sp:GSprite;
        private var _bmps:Array;
        private var _isDown:Boolean = true;
        private var _callback:Function;
        private var _bmp:GBitmap;
        private var _dh:int;
        private var _mask:GBitmap;

        public function BitmapNumberTextRolling()
        {
            return;
        }// end function

        public function init(param1:int, param2:int, param3:int, param4:int, param5:Array, param6:Boolean = false) : void
        {
            var _loc_10:int = 0;
            var _loc_11:GBitmap = null;
            this._isDown = param6;
            var _loc_7:int = 0;
            var _loc_8:int = 1;
            if (param6)
            {
                _loc_8 = -1;
            }
            this._sp = UICompomentPool.getUICompoment(GSprite);
            this.addChild(this._sp);
            this._bmps = [];
            var _loc_9:* = param1;
            while (_loc_9 < 30)
            {
                
                _loc_10 = _loc_9 % 10;
                _loc_11 = UICompomentPool.getUICompoment(GBitmap);
                _loc_11.y = param4 * (_loc_9 - param1) * _loc_8;
                this._dh = _loc_11.y;
                _loc_11.bitmapData = param5[_loc_10];
                this._bmps.push(_loc_11);
                this._sp.addChild(_loc_11);
                if (_loc_10 == param2 && _loc_7 >= 7)
                {
                    break;
                }
                _loc_9++;
                _loc_7++;
            }
            this._mask = UICompomentPool.getUICompoment(GBitmap);
            this._mask.bitmapData = param5[0];
            this.addChild(this._mask);
            this.mask = this._mask;
            return;
        }// end function

        public function rolling(param1:GBitmap, param2:Number = 1, param3:Function = null) : void
        {
            this._bmp = param1;
            this._callback = param3;
            this._sp.y = 0;
            this._bmp.visible = false;
            this._tween = TweenMax.to(this._sp, param2, {y:-this._dh, onComplete:this.tweenEnd});
            return;
        }// end function

        private function tweenEnd() : void
        {
            if (this._bmp != null)
            {
                this._bmp.visible = true;
                this._bmp = null;
            }
            if (this._callback != null)
            {
                this._callback.apply();
                this._callback = null;
            }
            DisplayUtil.delNotUse(this._bmps, 0);
            this._bmps = null;
            if (this._sp != null)
            {
                this._sp.dispose(true);
                this._sp = null;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this._tween != null)
            {
                this._tween.kill();
                this._tween = null;
            }
            if (this._bmp != null)
            {
                this._bmp.visible = true;
                this._bmp = null;
            }
            DisplayUtil.delNotUse(this._bmps, 0);
            this._bmps = null;
            if (this._sp != null)
            {
                this._sp.dispose(true);
                this._sp = null;
            }
            if (this._mask != null)
            {
                this._mask.dispose(param1);
                this._mask = null;
            }
            return;
        }// end function

    }
}
